<?php
namespace cms\modules\v1\models;

use common\models\Common;
use common\models\Functions;
use common\models\Status;
use common\services\upload\AliyunOSS;
use common\services\upload\Qiniu;
use common\utils\CodeImgGenerate;
use Yii;
use yii\base\Exception;
use yii\web\Response;

/**
 * This is the model class for table "goods".
 *
 * @property int $id
 * @property string $name
 */
class Captcha extends Common
{

    public function create() {
        $codeImgGenerate = new CodeImgGenerate();

        $codeImgGenerate->maxLength = 4;                         // 最大显示个数
        $codeImgGenerate->minLength = 4;                         // 最少显示个数
        $codeImgGenerate->padding  = 0;                          // 间距
        $codeImgGenerate->height = 58;                           // 高度
        $codeImgGenerate->width  = 156;                          // 宽度
        $codeImgGenerate->backColor = $codeImgGenerate::captchaColor(1);    // 背景颜色
        $codeImgGenerate->foreColor = $codeImgGenerate::captchaColor(2);    // 字体颜色
        $codeImgGenerate->offset = 4;                            // 字符之间的偏移量
        $codeInfo = $codeImgGenerate->inline();                  // 验证码二进制流
        $base64String = 'data:' . 'png' . ';base64,' . chunk_split(base64_encode($codeInfo));

        return Functions::formatRestAPI(0, '获取成功', $base64String);

    }
}
